package manager;

import entity.Province;
import iface.IManager;
import java.util.ArrayList;

/**
 *
 * @author Noi
 */
public class ProvinceManager implements IManager<Province> {

    private ArrayList<Province> provinceList;

    public ProvinceManager() {
        this.provinceList = new ArrayList<Province>();
    }

    @Override
    public boolean add(Province province) {
        return this.provinceList.add(province);
    }

    @Override
    public boolean remove(Province province) {
        return this.provinceList.remove(province);
    }

    @Override
    public Province replace(int index, Province obj) {
        return this.provinceList.set(index, obj);
    }
    
    @Override
    public int size() {
        return this.provinceList.size();
    }
    
    @Override
    public Province get(int index) {
        return this.provinceList.get(index);
    }

    @Override
    public Province getById(int id) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public Province getByID(String provinceID) {
        for(Province obj: this.provinceList) {
            if(obj.getProvinceID().equals(provinceID)) return obj;
        }
        return null;
    }
    
    @Override
    public Province getByName(String provinceName) {
        for(Province obj: this.provinceList) {
            if(obj.getProvinceName().equals(provinceName)) return obj;
        }
        return null;
    }
    
    public Province contains(String provinceID, String provinceName) {
        for(Province province: this.provinceList) {
            if(province.getProvinceName().equals(provinceName) || province.getProvinceID().equals(provinceID)) return province;
        }
        return null;
    }
    
    @Override
    public void setVisible(Province province, boolean value) {
        for(Province obj: this.provinceList) {
            if(obj.getProvinceID().equals(province.getProvinceID())) obj.setStatus(value);
        }
    }
}
